.syntax unified                 		  /*统一指令集语法*/
.cpu cortex-m3                  		  /*指定目标处理器*/
.thumb                          		  /*类似于.code 16,选择使用thumb指令集*/

.equ STACK_POINTER, 0x20000400  		  /*栈指针指向SRAM中的0x20000400处*/

.global __Vectors
.section .vectors,"a",%progbits			  /*定义一个名为“.vectors”的可分配的数据段*/
.type __Vectors, %object        		  /*将符号__Vectors标记为数据对象*/
.size __Vectors, .-__Vectors    		  /*此指令用于设置与符号关联的大小*/

/***********************************************************************
 *向量表的起始地址是有要求的：必须先求出系统中共有多少个向量，再把这个数字
 *向上增大到是2的整次幂，而起始地址必须对齐到后者的边界上。例如，如果一
 *共有32个中断，则共有32+16（系统异常）=48个向量，向上增大到2的整次幂后值
 *为64，因此地址地址必须能被64*4=256整除，从而合法的起始地址可以是：0x0,
 *0x100, 0x200 等。
 ***********************************************************************/

__Vectors:                                /*128*4=512字节的向量表*/
	.word  STACK_POINTER					  /*MSP 的初始值*/
	.word  Reset_Handler         		  /*复位向量（PC 初始值）*/
	.word  NMI_Handler          		  /*NMI 服务例程的入口地址*/
	.word  HardFault_Handler    		  /*硬 fault 服务例程的入口地址*/
	.word  MemManage_Handler    		  /*存储器管理 fault*/
	.word  BusFault_Handler     		  /*从总线系统收到了错误响应程序*/
	.word  UsageFault_Handler   		  /*由于程序错误导致的异常*/ 
	.word  0                    		  /*7-10的异常编号保留*/
	.word  0
	.word  0
	.word  0
	.word  SVC_Handler          		  /*执行系统服务调用指令（SVC）引发的异常*/
	.word  DebugMon_Handler     		  /*调试异常*/
	.word  0                     		  /*13号异常保留*/
	.word  PendSV_Handler       		  /*为系统设备而设的“可悬挂请求”异常*/
	.word  SysTick_Handler     		      /*系统滴答定时器异常*/
	.word  WWDG_IRQHandler      		  /*窗口定时器中断*/
	.word  PVD_IRQHandler       		  /*连到EXTI的电源电压检测(PVD)中断*/
	.word  TAMPER_IRQHandler    		  /*侵入检测中断*/
	.word  RTC_IRQHandler       		  /*实时时钟(RTC)全局中断*/
	.word  FLASH_IRQHandler     		  /*闪存全局中断*/
	.word  RCC_IRQHandler       		  /*复位和时钟控制(RCC)中断*/
	.word  EXTI0_IRQHandler     		  /*EXTI线0中断*/
	.word  EXTI1_IRQHandler               /*EXTI线1中断*/
	.word  EXTI2_IRQHandler               /*EXTI线2中断*/
	.word  EXTI3_IRQHandler               /*EXTI线3中断*/
	.word  EXTI4_IRQHandler               /*EXTI线4中断*/
	.word  DMA1_Channel1_IRQHandler       /*DMA1通道1全局中断*/
	.word  DMA1_Channel2_IRQHandler       /*DMA1通道2全局中断*/
	.word  DMA1_Channel3_IRQHandler       /*DMA1通道3全局中断*/
	.word  DMA1_Channel4_IRQHandler       /*DMA1通道4全局中断*/
	.word  DMA1_Channel5_IRQHandler       /*DMA1通道5全局中断*/
	.word  DMA1_Channel6_IRQHandler       /*DMA1通道6全局中断*/
	.word  DMA1_Channel7_IRQHandler       /*DMA1通道7全局中断*/
	.word  ADC1_2_IRQHandler              /*ADC1和ADC2全局中断*/
	.word  USB_HP_CAN1_TX_IRQHandler      /*CAN1发送中断*/
	.word  USB_LP_CAN1_RX0_IRQHandler     /*CAN1接收0中断*/
	.word  CAN1_RX1_IRQHandler            /*CAN1接收1中断*/
	.word  CAN1_SCE_IRQHandler            /*CAN1 SCE中断 */
	.word  EXTI9_5_IRQHandler             /*EXTI线[9:5]中断*/
	.word  TIM1_BRK_IRQHandler  		  /*TIM1刹车中断*/
	.word  TIM1_UP_IRQHandler             /*TIM1更新中断  */
	.word  TIM1_TRG_COM_IRQHandler        /*TIM1触发和通信中断*/
	.word  TIM1_CC_IRQHandler             /*TIM1捕获比较中断*/
	.word  TIM2_IRQHandler                /*TIM2全局中断*/
	.word  TIM3_IRQHandler                /*TIM3全局中断*/
	.word  TIM4_IRQHandler                /*TIM4全局中断*/
	.word  I2C1_EV_IRQHandler             /*I2C1事件中断*/
	.word  I2C1_ER_IRQHandler             /*I2C1错误中断*/
	.word  I2C2_EV_IRQHandler             /*I2C2事件中断*/
	.word  I2C2_ER_IRQHandler             /*I2C2错误中断*/
	.word  SPI1_IRQHandler                /*SPI1全局中断*/
	.word  SPI2_IRQHandler                /*SPI2全局中断*/
	.word  USART1_IRQHandler              /*USART1全局中断*/
	.word  USART2_IRQHandler              /*USART2全局中断*/
	.word  USART3_IRQHandler              /*USART3全局中断*/
	.word  EXTI15_10_IRQHandler           /*EXTI线[15:10]中断*/
	.word  RTCAlarm_IRQHandler            /*连到EXTI的RTC闹钟中断*/
	.word  USBWakeUp_IRQHandler           /*连到EXTI的全速USB OTG唤醒中断*/
	.word  TIM8_BRK_IRQHandler            /*TIM8刹车中断*/
	.word  TIM8_UP_IRQHandler             /*TIM8更新中断*/
	.word  TIM8_TRG_COM_IRQHandler        /*TIM8触发和通信中断*/
	.word  TIM8_CC_IRQHandler             /*TIM8捕获比较中断*/
	.word  ADC3_IRQHandler                /*ADC3全局中断*/
	.word  FSMC_IRQHandler                /*FSMC全局中断*/
	.word  SDIO_IRQHandler                /*SDIO全局中断*/
	.word  TIM5_IRQHandler                /*TIM5全局中断*/
	.word  SPI3_IRQHandler                /*SPI3全局中断*/
	.word  UART4_IRQHandler               /*UART4全局中断*/
	.word  UART5_IRQHandler               /*UART5全局中断*/
	.word  TIM6_IRQHandler                /*TIM6全局中断*/
	.word  TIM7_IRQHandler                /*TIM7全局中断*/
	.word  DMA2_Channel1_IRQHandler       /*DMA2通道1全局中断*/
	.word  DMA2_Channel2_IRQHandler       /*DMA2通道2全局中断*/
	.word  DMA2_Channel3_IRQHandler       /*DMA2通道3全局中断*/
	.word  DMA2_Channel4_5_IRQHandler     /*DMA2通道4和DMA2通道5全局中断*/
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0
	.word  0

/***********************************************************
 *为Default_Handler的每个Exception处理程序提供弱别名。
 *因为它们是弱别名，所以具有相同名称的任何函数都将覆盖此定义。
************************************************************/
	
.weak  NMI_Handler                              /*.weak表示弱定义*/
.thumb_set NMI_Handler,Default_Handler          /*.thumb_set表示如果没有重写中断处理函数，将使用默认的处理*/

.weak  HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler

.weak  MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler

.weak  BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler

.weak  UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler

.weak  SVC_Handler
.thumb_set SVC_Handler,Default_Handler

.weak  DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler

.weak  PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler

.weak  SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler

.weak  WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler

.weak  PVD_IRQHandler
.thumb_set PVD_IRQHandler,Default_Handler

.weak  TAMPER_IRQHandler
.thumb_set TAMPER_IRQHandler,Default_Handler

.weak  RTC_IRQHandler
.thumb_set RTC_IRQHandler,Default_Handler

.weak  FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler

.weak  RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler

.weak  EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler

.weak  EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler

.weak  EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler

.weak  EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler

.weak  EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler

.weak  DMA1_Channel1_IRQHandler
.thumb_set DMA1_Channel1_IRQHandler,Default_Handler

.weak  DMA1_Channel2_IRQHandler
.thumb_set DMA1_Channel2_IRQHandler,Default_Handler

.weak  DMA1_Channel3_IRQHandler
.thumb_set DMA1_Channel3_IRQHandler,Default_Handler

.weak  DMA1_Channel4_IRQHandler
.thumb_set DMA1_Channel4_IRQHandler,Default_Handler

.weak  DMA1_Channel5_IRQHandler
.thumb_set DMA1_Channel5_IRQHandler,Default_Handler

.weak  DMA1_Channel6_IRQHandler
.thumb_set DMA1_Channel6_IRQHandler,Default_Handler

.weak  DMA1_Channel7_IRQHandler
.thumb_set DMA1_Channel7_IRQHandler,Default_Handler

.weak  ADC1_2_IRQHandler
.thumb_set ADC1_2_IRQHandler,Default_Handler

.weak  USB_HP_CAN1_TX_IRQHandler
.thumb_set USB_HP_CAN1_TX_IRQHandler,Default_Handler

.weak  USB_LP_CAN1_RX0_IRQHandler
.thumb_set USB_LP_CAN1_RX0_IRQHandler,Default_Handler

.weak  CAN1_RX1_IRQHandler
.thumb_set CAN1_RX1_IRQHandler,Default_Handler

.weak  CAN1_SCE_IRQHandler
.thumb_set CAN1_SCE_IRQHandler,Default_Handler

.weak  EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler

.weak  TIM1_BRK_IRQHandler
.thumb_set TIM1_BRK_IRQHandler,Default_Handler

.weak  TIM1_UP_IRQHandler
.thumb_set TIM1_UP_IRQHandler,Default_Handler

.weak  TIM1_TRG_COM_IRQHandler
.thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler

.weak  TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler

.weak  TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler

.weak  TIM3_IRQHandler
.thumb_set TIM3_IRQHandler,Default_Handler

.weak  TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler

.weak  I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler

.weak  I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler

.weak  I2C2_EV_IRQHandler
.thumb_set I2C2_EV_IRQHandler,Default_Handler

.weak  I2C2_ER_IRQHandler
.thumb_set I2C2_ER_IRQHandler,Default_Handler

.weak  SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler

.weak  SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler

.weak  USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler

.weak  USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler

.weak  USART3_IRQHandler
.thumb_set USART3_IRQHandler,Default_Handler

.weak  EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler

.weak  RTCAlarm_IRQHandler
.thumb_set RTCAlarm_IRQHandler,Default_Handler

.weak  USBWakeUp_IRQHandler
.thumb_set USBWakeUp_IRQHandler,Default_Handler

.weak  TIM8_BRK_IRQHandler
.thumb_set TIM8_BRK_IRQHandler,Default_Handler

.weak  TIM8_UP_IRQHandler
.thumb_set TIM8_UP_IRQHandler,Default_Handler

.weak  TIM8_TRG_COM_IRQHandler
.thumb_set TIM8_TRG_COM_IRQHandler,Default_Handler

.weak  TIM8_CC_IRQHandler
.thumb_set TIM8_CC_IRQHandler,Default_Handler

.weak  ADC3_IRQHandler
.thumb_set ADC3_IRQHandler,Default_Handler

.weak  FSMC_IRQHandler
.thumb_set FSMC_IRQHandler,Default_Handler

.weak  SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler

.weak  TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler

.weak  SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler

.weak  UART4_IRQHandler
.thumb_set UART4_IRQHandler,Default_Handler

.weak  UART5_IRQHandler
.thumb_set UART5_IRQHandler,Default_Handler

.weak  TIM6_IRQHandler
.thumb_set TIM6_IRQHandler,Default_Handler

.weak  TIM7_IRQHandler
.thumb_set TIM7_IRQHandler,Default_Handler

.weak  DMA2_Channel1_IRQHandler
.thumb_set DMA2_Channel1_IRQHandler,Default_Handler

.weak  DMA2_Channel2_IRQHandler
.thumb_set DMA2_Channel2_IRQHandler,Default_Handler

.weak  DMA2_Channel3_IRQHandler
.thumb_set DMA2_Channel3_IRQHandler,Default_Handler

.weak  DMA2_Channel4_5_IRQHandler
.thumb_set DMA2_Channel4_5_IRQHandler,Default_Handler
	
.text                                          /*代码段*/
.global Default_Handler
.type Default_Handler, %function			   /*默认异常中断处理函数*/
Default_Handler:
	b Default_Handler
.size Default_Handler, .-Default_Handler

.global Reset_Handler                          /*全局标号*/
.type Reset_Handler, %function                 /*定义函数*/
Reset_Handler:								   /*复位处理函数*/
	ldr  r0, =_data_start
	ldr  r1, =_data_end
	subs r2, r1, r0                            /*求data段大小*/
	beq  is_bss                                /*如果data段大小为0，跳到is_bss标号*/
	ldr  r3, =_ram_data_start                  /*data段在sram中的起始位置*/
copy_data:                                     /*从Flash中复制data段的数据到sram中*/ 
	ldr  r4, [r0,#0]                           /*从Flash加载数据*/
	str  r4, [r3,#0]                           /*写入到sram中*/
	add  r0, #4
	add  r3, #4
	cmp  r0, r1                                /*比较r0,r1,是否复制完*/
	bne  copy_data
is_bss:
	ldr  r0, =_bss_start                        
	ldr  r1, =_bss_end
	subs r2, r1, r0                            /*求bss段大小*/
	beq  no_init_bss                           /*bss段大小为0，不用初始化*/
	ldr  r3, =0x00000000
init_bss:                                      /*开始初始化bss段*/
	str  r3, [r0,#0]                           /*向bss段写入0，即bss段数据初始化为0*/
	add  r0, #4
	cmp  r0, r1
	bne  init_bss
no_init_bss:
	bl SystemInit                              /*带返回值的跳转指令，跳转到SystemInit处执行*/
	ldr r0, =test_led                          /*将main函数的地址存入r0*/
	bx  r0                                     /*带状态切换的跳转指令，跳转到main处执行*/
	.end                                       /*文件结束*/
	